<template>
  <div class="children-table">
    <d2-crud
      ref="d2Crud"
      :columns="columns"
      :data="dataTable"
      :options="options"
       @row-click="rowClick"
      index-row
      selection-row
      @selection-change="selectChange"
      @current-change="handleCurrentChange"
      :pagination="pagination"
      @pagination-current-change="paginationCurrentChange"
    >
      <div class="title" slot="header">
        <span class="text">法规法条列表</span>
        <head-btns :add="add" :mod="edit" :del="del" />
      </div>

      <!-- <el-button slot="header" type="primary" style="margin-bottom: 5px" @click="addDept" icon="el-icon-circle-plus">添加</el-button>
      <el-button slot="header" type="success" style="margin-bottom: 5px" @click="editDept" icon="el-icon-edit">修改</el-button>
      <el-button slot="header" type="danger" style="margin-bottom: 5px" @click="delDept" icon="el-icon-delete">删除</el-button>-->
    </d2-crud>
    <edit-form :dept="dept" v-model="editFormVisible" @submit="legalDetailList" />
    <add-form :temp="temp" v-model="addFormVisible" @submit="legalDetailList"></add-form>
  </div>
</template>

<script>
import itemsApi from "@/api/system/caseCauselawcontent";
import editForm from "./edititems";
import addForm from "./additems";
import HeadBtns from "@/views/comps/zhzf/head-btns";
export default {
  name: "legal-items",
  components: { editForm, addForm, HeadBtns },
  props: {
    scope: {
      default: null
    }
  },
  data() {
    return {
      columns: [
        {
          title: "法规名称",
          key: "strName",
          width: "180"
        },
        {
          title: "法条编码",
          key: "code",
          width: "120"
        },
        {
          title: "条",
          key: "item",
          width: "50"
        },
        {
          title: "违反条例",
          key: "yjtl",
          width: "200"
        },
        {
          title: "罚款上限",
          key: "upperLimit",
          width: "100"
        },
        {
          title: "罚款下限",
          key: "lawerLimit",
          width: "100"
        },
        {
          title: "处罚标准",
          key: "cfbz"
        }
      ],
      data: [],
      dataTable: [],
      options: {
        stripe: true,
        highlightCurrentRow: true
      },
      currentId: null,
      editFormVisible: false,
      dept: {},
      temp: {},
      addFormVisible: false,
      pagination: {
        currentPage: 1,
        pageSize: 10,
        total: 0
      },
      selected: []
    };
  },
  mounted() {
    this.legalDetailList();
  },
  methods: {
    //根据法律法规查询法条
    legalDetailList() {
      this.lawInfo = this.scope.row;
      var param = { lawContentId: this.lawInfo.bnslawId };
      Object.assign(this.pagination,param);
      itemsApi.Page(this.pagination).then(res => {
        var data = res.data;
        this.data = data.rows;
        this.dataTable = data.rows;
        this.pagination.total = data.total;
      });
    },
    paginationCurrentChange(currentPage) {
      this.pagination.currentPage = currentPage;
      this.getTableData();
    },
    selectChange(selection) {
      //多选
      this.selected = selection;
    },
    add() {
      if (this.lawInfo.bnslawId) {
        this.temp = {
          lawContentId: this.scope.row.bnslawId,
          strName: this.scope.row.strName
        };
      }

      this.addFormVisible = true;
    },
    rowClick(row) {
      this.$refs.d2Crud.$children[1].toggleRowSelection(row);
    },
    handleCurrentChange(currentRow) {
      if (currentRow) {
        this.currentId = currentRow.id;
      }
    },

    edit() {
      if (this.currentId) {
        for (let i = 0; i < this.data.length; i++) {
          if (this.data[i].id == this.currentId) {
            this.dept = this.data[i];
          }
        }
        this.editFormVisible = true;
      }
    },
    del() {
      this.$confirm("确认删除？", "确认信息", {
        distinguishCancelAndClose: true,
        confirmButtonText: "删除",
        cancelButtonText: "取消"
      }).then(() => {
        itemsApi.del({ id: this.currentId }).then(() => {
          this.legalDetailList();
          this.currentId = null;
        });
      });
    }
  }
};
</script>
<style lang="scss">
.el-table__expanded-cell {
  padding: 0 !important;

  .children-table {
    background: #f0f0f0;
    padding-left: 50px;
    padding-bottom: 10px;
    .title {
      background: transparent;
    }
    .d2-crud {
      border: 1px solid #ccc;
      border-top: 0;
    }
  }
}
</style>